#!/bin/sh
# System startup script for kliqj 3d-printer host code

### BEGIN INIT INFO
# Provides:          kliqj
# Required-Start:    $local_fs
# Required-Stop:
# Default-Start:     2 3 4 5
# Default-Stop:      0 1 6
# Short-Description: kliqj daemon
# Description:       Starts the kliqj daemon.
### END INIT INFO
port1=8080
port2=8081
function status_msg() {
  echo -e "\n${magenta}#### ${1}${white}"
}
LD_PRELOAD=/home/print3D/ioctlHook.so
chmod -R 777 ${home}/home/print3D/printer_data
case "$1" in
start)  status_msg "启动全家桶"
        LD_PRELOAD=/home/print3D/ioctlHook.so rc-service klipper start
        LD_PRELOAD=/home/print3D/ioctlHook.so rc-service moonraker start
        rc-service nginxk  start
        grep "false" /root/print3D/ksdelay.sh > /dev/null
        if [ $? -ne 0 ]; then
          LD_PRELOAD=/home/print3D/ioctlHook.so rc-service KlipperScreen start
        fi
        status_msg "全家桶启动完成"
        ;;
stop)   status_msg "停止全家桶"
        grep "false" /root/print3D/ksdelay.sh > /dev/null
        if [ $? -ne 0 ]; then
           rc-service KlipperScreen stop
        fi
        rc-service nginxk  stop
        rc-service moonraker stop
        rc-service klipper stop
        status_msg "已停止全家桶"
        ;;
restart) status_msg "重新启动全家桶"
        $0 stop
        $0 start
        ;;
esac
exit 0